package com.clientes;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.net.ParseException;
import android.util.Log;

import com.eventos.EventoBean;
import com.google.gson.stream.JsonReader;
import com.eventssmartphone.JSONReader;
import com.eventssmartphone.JSONReaderListener;
public class GestorRating {

private static final GestorRating gestor = new GestorRating();
	
	public static GestorRating getInstance(){
		return gestor;
	}
	
	
	public void dameRatingJson(Context context, int idCliente, int idEvento){
		
		JSONReader jReader = new JSONReader();
		jReader.setJSONReaderListener((JSONReaderListener)context);
		jReader.execute("http://200.16.7.112:3000/client_management/clients/dame_rating_by_client/"+idCliente + "/" + idEvento +".json");
	}
	
	public int procesarDameRating(JSONArray jRating){
		int hayRating;
		Log.i("JSONMARGA",jRating.toString());
		
		if (jRating.length() <=0){
			Log.i("JSONMARGA","json vacio");
			return -1;
		}else {
		try{
				Log.i("JSONMARGA","no es vacio");
				
				hayRating = jRating.getJSONObject(0).getJSONObject("rating_client").getInt("rating");
			return hayRating;
		}catch(JSONException e){
			Log.e("log_tag", "Error parsing data "+e.toString());
			return -1;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return -1;
		}}
	}
	
	}
